package org.gitos.cloud.cmd.controller;

import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import org.apache.zookeeper.Login;
import org.gitos.cloud.domain.rpc.LogicRPC;
import org.gitos.cloud.domain.rpc.LoginRPC;
import org.gitos.cloud.domain.server.Rom;
import org.gitos.cloud.domain.server.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LogicController extends BaseController {
    private static final Logger log = LoggerFactory
            .getLogger(LogicController.class);

    @Reference
    LogicRPC logicRPC;

    @RequestMapping("/logic/leds")
    public Map<String, Object> leds(HttpServletRequest request) {
        return logicRPC.leds(request.getAttribute("userId").toString());
    }

    @RequestMapping("/logic/bindInuser")
    public Map<String, Object> bindInuser(HttpServletRequest request, @RequestParam(name = "mobile_os") String mobile_os,
                                          @RequestParam(name = "inuser_token") String inuser_token) {
        return logicRPC.bindInuser(request.getAttribute("userId").toString(), mobile_os, inuser_token);
    }

    @RequestMapping("/logic/bindLed")
    public Map<String, Object> bindLed(HttpServletRequest request,
                                       @RequestParam(name = "mac") String mac) {
        return logicRPC.bindLed(request.getAttribute("userId").toString(), mac);
    }

    @RequestMapping("/logic/wifiRoms")
    public Map<String, Object> wifiRoms(HttpServletRequest request, @RequestParam(name = "mac") String mac, String version) {
        return success(logicRPC.roms(mac, version, Rom.WIFI_ROM));
    }

    @RequestMapping("/logic/mcuRoms")
    public Map<String, Object> mcuRoms(HttpServletRequest request, @RequestParam(name = "mac") String mac, String version) {
        return success(logicRPC.roms(mac, version, Rom.MCU_ROM));
    }

}
